package com.xjve.framework.hibernate.jpa;

import lombok.Getter;
import lombok.Setter;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Map;

/**
 * 查询字段元数据
 */
@Getter
@Setter
public class SearchFieldMetadata {
    private final Field field;
    private final String fieldName;
    private final Object fieldValue;
    private final Map<Class<? extends Annotation>, Annotation> annotations;
    private final String actualFieldName;
    private final String operator;
    private final Object processedValue;
    private final String paramName;

    public SearchFieldMetadata(Field field, String fieldName, Object fieldValue,
                              Map<Class<? extends Annotation>, Annotation> annotations,
                              String actualFieldName, String operator,
                              Object processedValue, String paramName) {
        this.field = field;
        this.fieldName = fieldName;
        this.fieldValue = fieldValue;
        this.annotations = annotations;
        this.actualFieldName = actualFieldName;
        this.operator = operator;
        this.processedValue = processedValue;
        this.paramName = paramName;
    }


    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
        return (T) annotations.get(annotationClass);
    }

    public boolean hasAnnotation(Class<? extends Annotation> annotationClass) {
        return annotations.containsKey(annotationClass);
    }
}
